package com.google.code.mochaccino.framework.ui.components;
/*
 * Copyright 2012 Claude Houle claude.houle@gmail.com
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 * <p>
 * The Option class exist for the sole purpose of easily representing a choice for a select-box. This construct
 * is compatible for the following macros:
 * <ul>
 * <li>ui-select.ftl</li>
 * <li>ui-select-chosen.ftl</li>
 * <li>ui-select-chosen-multi.ftl</li>
 * </ul>
 * </p>
 */
public class Option {

	/** The Css Classname */
	private String css = null;

	/** The Label */
	private String label = null;

	/** The Value */
	private String value = "";

	/** Selection Flag */
	private boolean selected = false;

	/** Constructor */
	public Option( String value, String label, boolean selected ) {
		this( value, label, selected, null );
	}

	/** Constructor */
	public Option( String label, boolean selected ) {
		this( label, label, selected, null );
	}

	/** Constructor */
	public Option( String label, boolean selected, String css ) {
		this( label, label, selected, css );
	}

	/** Constructor */
	public Option( String label ) {
		this( label, label, false, null );
	}

	/** Constructor */
	public Option( String label, String css ) {
		this( label, label, false, css );
	}

	/** Constructor */
	public Option( String value, String label, boolean selected, String css ) {
		this.value = value;
		this.label = label;
		this.selected = selected;
		this.css = css;
	}

	@Override
	public boolean equals( Object o ) {
		if ( o instanceof Option ) {
			Option opt = (Option) o;
			if ( value.equals( opt.value ) ) {
				return true;
			}
		}
		return super.equals( o );
	}

	/** @return the cssClassName */
	public String getCss() {
		return css;
	}

	/** @param css the cssClassName to set */
	public void setCss( String css ) {
		this.css = css;
	}

	/** @return the label */
	public String getLabel() {
		return label;
	}

	/** @param label the label to set */
	public void setLabel( String label ) {
		this.label = label;
	}

	/** @return the value */
	public String getValue() {
		return value;
	}

	/** @param value the value to set */
	public void setValue( String value ) {
		this.value = value;
	}

	@Override
	public int hashCode() {
		return value.hashCode();
	}

	/** @return the selected */
	public boolean isSelected() {
		return selected;
	}

	/** @param selected the selected to set */
	public void setSelected( boolean selected ) {
		this.selected = selected;
	}

	@Override
	public String toString() {
		return value;
	}
}